﻿using FieldTools.Client.View.Control;
using FieldTools.Util;
using MahApps.Metro.Controls;
using System;
using System.Windows;
using System.Windows.Controls;

namespace FieldTools.Client.View.Window
{
    /// <summary>
    /// TCPServerControl.xaml 的交互逻辑
    /// </summary>
    public partial class TCPServerWindow : MetroWindow, ITransientDependency
    {
        /// <summary>
        /// 是否已打开窗口（定义该静态属性后即表示当前窗口仅能打开一个）
        /// </summary>
        public static bool IsOpened { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public TCPServerWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            BlankControl blankControl = new("页面已在新窗口打开");
            TCPServerWindow _this = this;
            button.IsEnabled = false;
            button.Visibility = Visibility.Collapsed;
            var window = new MetroWindow()
            {
                Content = _this.Content
            };
            window.Closed += Window_Closed;

            window.Show();
            this.Content = blankControl;
        }

        private void Window_Closed(object? sender, EventArgs e)
        {
            if (sender != null)
                (sender as MetroWindow).Close();
            button.Visibility = Visibility.Visible;
            button.IsEnabled = true;
            this.Content = new TCPServerWindow();
        }
    }
}
